package com.depth.viewer.events
{
	
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.utils.Dictionary;
	
	
	public class EventBus extends EventDispatcher
	{
		private static var _eventBusList:Dictionary = new Dictionary();
		private static var _eventBus:EventBus;
		
		private static var lock:Boolean = false;
		
		public var id:String;
		public function EventBus()
		{
			if (!lock)
			{
				throw new Error("ContainerEventDispatcher can only be defined once!");
			}
		}
		
		
		public static function getInstance(key:String = "public"):EventBus
		{
			_eventBus = _eventBusList[key] as EventBus;
			if (_eventBus == null)
			{
				lock = true;
				_eventBus = new EventBus();
				_eventBus.id = key;
				_eventBusList[key] = _eventBus;
				lock = false;
			}
			return _eventBus;
		}
		
		
		
		public function dispatch(type:String):Boolean
		{
			return dispatchEvent(new Event(type));
		}
	}
	
}
